﻿using System;
using System.Web;

namespace Uranus.Common
{
    public class ShortLinkCommon
    {
        public static string ShortLink(string longurl)
        {
            if (!string.IsNullOrEmpty(longurl))
            {
                string result = Common.RequestCommon.SimulationHttp("http://dwz.cn/create.php", string.Format("url={0}", HttpUtility.UrlEncode(longurl)), "post");
                ShortData shortData = Common.CodeCommon.DeSerialize<ShortData>(result);
                if (shortData != null && !string.IsNullOrEmpty(shortData.tinyurl))
                {
                    return shortData.tinyurl;
                }
            }
            return string.Empty;
        }
    }

    [Serializable]
    internal class ShortData
    {
        public string tinyurl { get; set; }
        public int status { get; set; }
        public string longurl { get; set; }
        public string err_msg { get; set; }
    }
}